/*
 * Slf4JErrorListener.java
 *
 * Copyright 2010 Jack Leow
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package my.edu.clhs.stringtemplate.servlet;

import org.antlr.stringtemplate.StringTemplateErrorListener;
import org.slf4j.Logger;

/**
 * Simple {@link StringTemplateErrorListener} implementation that delegates to
 * a SLF4J {@link Logger}.
 *
 * @author Jack Leow
 * @version 1.0
 * @since 1.0 (Feb 28, 2010, 5:57:14 PM)
 */
public class Slf4JErrorListener implements StringTemplateErrorListener {
    private final Logger log;
    
    public Slf4JErrorListener(Logger log) {
        if (log == null) {
            throw new NullPointerException("log cannot be null");
        }
        this.log = log;
    }

    public void error(String msg, Throwable e) {
        if (e != null) {
            log.error(msg, e);
        } else {
            log.error(msg);
        }
    }

    public void warning(String msg) {
        log.warn(msg);
    }
}
